package com.example.petcare.mapper;


import com.example.petcare.pojo.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface UserMapper {
    // 根据用户名查询用户
    @Select("select * from user where username=#{username}")
    User findByUsername(String username);

    // 注册用户
    @Insert("insert into user(username, password, create_time, update_time)" +
            "values(#{username}, #{password}, now(), now())")
    void addUser(String username, String password);

    // 更新用户数据
    @Update("update user set nickname=#{nickname}, email=#{email}, phone=#{phone} , address=#{address},update_time=#{updateTime} ,audit_status = 0 where user_id=#{userId}")
    void update(User user);

    // 更新密码
    @Update("update user set password=#{md5String},update_time=now() where user_id=#{userId}")
    void updatePwd(String md5String, Integer userId);

    // 根据用户id查询用户
    @Select("select * from user where user_id=#{id}")
    User findById(Integer id);
}
